//
//  RegistViewController.m
//  UIProject-A
//
//  Created by lanou3g on 15/7/16.
//  Copyright (c) 2015年 何 旭. All rights reserved.
//

#import "RegistViewController.h"
#import "RegistView.h"
#import "LTView.h"
#import "MainCollectionViewController.h"

@interface RegistViewController ()<UITextFieldDelegate>
@property (nonatomic,retain) RegistView * registView;
@end

@implementation RegistViewController

-(void)loadView{
    self.view = [[RegistView alloc]initWithFrame:[UIScreen mainScreen].bounds];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"注 册";
  self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"2.png"]];
    
   RegistView *registerView = (RegistView *)self.view;
    //输入框
    registerView.usernameView.TextField.delegate = self;
    registerView.passwordView.TextField.delegate = self;
     registerView.passwordsureView.TextField.delegate = self;
    registerView.phoneLTView.TextField.delegate = self;
    registerView.mailLTView.TextField.delegate = self;
    
    //取消按钮
    [registerView.cancelButton addTarget:self action:@selector(cancelButton:) forControlEvents:UIControlEventTouchUpInside];
    //确定按钮
    [registerView.sureButton addTarget:self action:@selector(sureButton:) forControlEvents:UIControlEventTouchUpInside];

}




#pragma mark - 按钮方法
//确定按钮
- (void)sureButton:(UIButton *)button {
    
    RegistView *registView = (RegistView *)self.view;
    if (registView.usernameView.TextField.text.length > 0 && registView.passwordView.TextField.text.length > 0 ) {
        if ([registView.passwordView.TextField.text isEqualToString:registView.passwordsureView.TextField.text]) {
//            MainViewController *rootVC = (MainViewController *)self.parentViewController;
            
        }else{
            UIAlertView *errorAlerView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"两次密码不同，请重新输入" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [errorAlerView show];
            
        }
        
    }else{
        UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"信息输入不正确，请重新输入" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [errorAlertView show];
    }
    
    //注册完成后，返回登陆页面
    [self.navigationController popViewControllerAnimated:YES];
    
   }


//取消按钮
-(void)cancelButton:(UIButton *)button{
    
}


#pragma mark - 代理方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
   RegistView *registerView = (RegistView *)self.view;
    
    if (textField == registerView.usernameView.TextField) {
        
        [registerView.passwordView.TextField becomeFirstResponder];
    } else if(textField == registerView.passwordView.TextField){
        [registerView.passwordsureView.TextField becomeFirstResponder];
    } else if(textField == registerView.passwordsureView.TextField){
        [registerView.mailLTView.TextField becomeFirstResponder];
    } else if(textField == registerView.mailLTView.TextField){
        [registerView.phoneLTView.TextField becomeFirstResponder];
    } else {
        [registerView.phoneLTView.TextField resignFirstResponder];
    }
    return self;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
